import axios from 'axios'
import { ElMessage } from 'element-plus'

//创建axios实例对象
const request = axios.create({
  baseURL: 'https://apifoxmock.com/m1/5222417-0-default',
  timeout: 600000
})

//axios的响应 response 拦截器
request.interceptors.response.use(
  (result) => { //成功回调
    if(!result.data.code){  //操作失败，弹出错误提示信息
      ElMessage.error(result.data.msg)
    }else{  //操作成功
      if(!result.data.data){   //data中没有数据说明是增删改操作，弹出提示信息
        ElMessage.success(result.data.msg)
      }
      return result.data
    }
  },(error) => { //失败回调
    return Promise.reject(error)
  }
)

export default request